package com.example.myfirstapplication.slice;

import com.example.myfirstapplication.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;

public class MainAbilitySlice extends AbilitySlice {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);

        Button button = (Button) findComponentById(ResourceTable.Id_button);

        if (button != null) {
            // 为按钮设置点击事件回调
            // 此处使用了 lambda 表达式 等同于以下代码：
            //       button.setClickedListener(new Component.ClickedListener() {
            //                @Override
            //                public void onClick(Component component) {}
            //       });
            button.setClickedListener(component -> {
//                    Intent secondIntent = new Intent();
//                    // 指定待启动FA的bundleName和abilityName
//                    Operation operation = new Intent.OperationBuilder()
//                            .withDeviceId("")
//                            .withBundleName("com.example.myfirstapplication")
//                            .withAbilityName("com.example.myfirstapplication.SecondAbility")
//                            .build();
//                    secondIntent.setOperation(operation);
//                    startAbility(secondIntent); // 通过AbilitySlice的startAbility接口实现启动另一个页面
                present(new SecondAbilitySlice(),new Intent());
            });
        }
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
